/*
 * FileManager.h
 *
 *  Created on: 7 июн. 2022 г.
 *      Author: nikita
 */

#ifndef SRC_TECHNICAL_FILEMANAGER_H_
#define SRC_TECHNICAL_FILEMANAGER_H_

#include "../STL_includes.h"
#include "Config.h"
#include "RuntimeErrorClass.h"
#include "../Typedefs.h"
#include "Logger.h"

#include <fstream>

namespace STC_calc
{

class StringFile
{
private:
	const std::string file_name;
	const std::fstream::openmode mode;
	std::shared_ptr<std::vector<std::string>> buffer;
	long pos;
	bool endfile;

	void read_all();
	void write_all();
public:
	StringFile(const std::string& file_name, const std::fstream::openmode openmode);
	~StringFile();

	std::shared_ptr<string_vector> get_buffer() {return buffer;}
	void write(const std::string& str);
};

class FileManager
{
private:
	FileManager();
	~FileManager();
public:
	static std::shared_ptr<string_vector> load_args(const std::string& file_name);
	static std::shared_ptr<string_vector> load_configs(const std::string& file_name = "~default");
	static std::shared_ptr<string_vector> load_help_text(const std::string& file_name = "help.txt");

	static void save_result(const long double& result, const std::string& file_name = "~default");
	static void save_log(const std::string& log, const std::string& file_name = "~default");
};

} /* namespace STC_calc */

#endif /* SRC_TECHNICAL_FILEMANAGER_H_ */
